/**
  ******************************************************************************
  * @file    tc32l010_pwr.h
  * @author  CHIPAT Application Team
  * @brief   This file contains all the functions prototypes for the PWR firmware
  *          library.
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __XS32L010_PWR_H
#define __XS32L010_PWR_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "tc32l010.h"
#include "tc32l010_rcc.h"

/** @addtogroup XS32L010_StdPeriph_Driver
  * @{
  */

/** @addtogroup PWR
  * @{
  */ 

/* Exported types ------------------------------------------------------------*/
typedef struct
{
    uint32_t En:1;
    uint32_t Act:1;
    uint32_t VccSel:2;
    uint32_t RefSel:3;
    uint32_t CtrlEN:1;
    uint32_t FltEn:1;
    uint32_t Reserved1:3;
    uint32_t FtEn:1;
    uint32_t RtEn:1;
    uint32_t HtEn:1;
    uint32_t IntEn:1;
    uint32_t FltNum:10;
    uint32_t Reserved2:6;
}LVD_CR_STRUCT;

typedef union {
    uint32_t Data;
    LVD_CR_STRUCT LVD_CR;  /* !< LVD Status Register Value. */
}LVD_Config_U;


/* Exported constants --------------------------------------------------------*/

/** @defgroup PWR_Exported_Constants
  * @{
  */ 

/** @defgroup PWR_LDO_Status 
  * @{
  */ 

#define PWR_LDO_MAST                    ((uint16_t)0x0000)
#define PWR_LDO_LOWPOWER                ((uint16_t)0x0100)

#define IS_PWR_LDO_STATUS(STATUS) (((STATUS) == PWR_LDO_MAST) || ((STATUS) == PWR_LDO_LOWPOWER))
/**
  * @}
  */

#define PWR_MLDO_1V2      0
#define PWR_MLDO_0V9      1
#define PWR_ULPLDO_1V2    2
#define PWR_ULPLDO_0V9    3
#define PWR_VREF_1V2      4
#define PWR_VREF_0V7      5

/** @defgroup PWR_LDO_VAULE 
  * @{
  */ 

#define PWR_VOLTAGE_VALUE_MIN           ((uint8_t)0x00)
#define PWR_VOLTAGE_VALUE_MAX           ((uint8_t)0x1F)

#define IS_PWR_LDO_VOLTAGE(VOLTAGE) (((VOLTAGE) >= PWR_VOLTAGE_VALUE_MIN) && ((VOLTAGE) <= PWR_VOLTAGE_VALUE_MAX))
/**
  * @}
  */
  
/**
  * @}
  */
  
/** @defgroup SRAM_RETAIN_mode 
  * @{
  */

#define SRAM_RETAIN_MODE_0                  ((uint8_t)0x00)
#define SRAM_RETAIN_MODE_1                  ((uint8_t)0x01)
#define IS_SRAM_RETAIN_MODE(MODE)      (((MODE) == SRAM_RETAIN_MODE_0) || \
                                        ((MODE) == SRAM_RETAIN_MODE_1))
/**
  * @}
  */

/** @defgroup PWR_run_mode_entry 
  * @{
  */

#define PWR_RUN_MODE0                   ((uint32_t)0x00000000)
#define PWR_RUN_MODE1                   ((uint32_t)0x00000400)
#define PWR_LPRUN_MODE0                 ((uint32_t)0x00000100)
#define PWR_LPRUN_MODE1                 ((uint32_t)0x00000900)
#define IS_PWR_RUNMODE(MODE)           (((MODE) == PWR_RUN_MODE0)  || ((MODE) == PWR_RUN_MODE1) ||\
                                        ((MODE) == PWR_LPRUN_MODE0)|| ((MODE) == PWR_LPRUN_MODE1))
 
/**
  * @}
  */
  
/** @defgroup PWR_LSI_state_is_Sleep_STOP_mode 
  * @{
  */

#define PWR_SLEEPMODE_0                ((uint32_t)0x00000000)
#define PWR_SLEEPMODE_1                ((uint32_t)0x00000400)
#define PWR_LPSLEEPMODE_0              ((uint32_t)0x00000100)
#define PWR_LPSLEEPMODE_1              ((uint32_t)0x00000900)
#define IS_PWR_SLEEPMODE(SLEEPMODE)   (((SLEEPMODE) == PWR_SLEEPMODE_0)  || \
                                       ((SLEEPMODE) == PWR_SLEEPMODE_1)  || \
                                       ((SLEEPMODE) == PWR_LPSLEEPMODE_0)|| \
                                       ((SLEEPMODE) == PWR_LPSLEEPMODE_1))
/**
  * @}
  */

/** @defgroup PWR_STOP_mode_entry 
  * @{
  */

#define PWR_STOPEntry_WFI               ((uint8_t)0x01)
#define PWR_STOPEntry_SLEEPONEXIT       ((uint8_t)0x02)
#define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) ||\
                                  ((ENTRY) == PWR_STOPEntry_SLEEPONEXIT))
 
/**
  * @}
  */
  
/** @defgroup PWR_LSI_state_is_Sleep_STOP_mode 
  * @{
  */

#define PWR_STOPMODE_0_LPVOS0           ((uint32_t)0x00000000)
#define PWR_STOPMODE_0_LPVOS1           ((uint32_t)0x00000004)
#define PWR_STOPMODE_1_LPVOS0           ((uint32_t)0x00000001)
#define PWR_STOPMODE_1_LPVOS1           ((uint32_t)0x00000005)
#define PWR_STOPMODE_2_LPVOS0           ((uint32_t)0x00000002)
#define PWR_STOPMODE_2_LPVOS1           ((uint32_t)0x00000006)
#define IS_PWR_STOPMODE(STOPMODE)      (((STOPMODE) == PWR_STOPMODE_0_LPVOS0) || \
                                        ((STOPMODE) == PWR_STOPMODE_0_LPVOS1) || \
                                        ((STOPMODE) == PWR_STOPMODE_1_LPVOS0) || \
                                        ((STOPMODE) == PWR_STOPMODE_1_LPVOS1) || \
                                        ((STOPMODE) == PWR_STOPMODE_2_LPVOS0) || \
                                        ((STOPMODE) == PWR_STOPMODE_2_LPVOS1))
/**
  * @}
  */

/** @defgroup PWR_Flag 
  * @{
  */

#define PWR_FLAG_LVD_INTF                LVD_SR_INTF
#define PWR_FLAG_LVD_FILTER              LVD_SR_FILTER

#define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_LVD_INTF) || ((FLAG) == PWR_FLAG_LVD_FILTER))

#define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_LVD_INTF))

/** @defgroup LVD_CR 
  * @{
  */

#define LVD_VCC_SEL_POWER               ((uint8_t)0x00)
#define LVD_VCC_SEL_PC5                 ((uint8_t)0x01)
#define IS_LVD_VCC_SEL(SEL)            (((SEL) == LVD_VCC_SEL_POWER) || ((SEL) == LVD_VCC_SEL_PC5))
 
#define LVD_REF_SEL_1V7                 ((uint8_t)0x00)
#define LVD_REF_SEL_1V8                 ((uint8_t)0x01)
#define LVD_REF_SEL_2V0                 ((uint8_t)0x02)
#define LVD_REF_SEL_2V2                 ((uint8_t)0x03)
#define LVD_REF_SEL_2V4                 ((uint8_t)0x04)
#define LVD_REF_SEL_2V6                 ((uint8_t)0x05)
#define LVD_REF_SEL_2V8                 ((uint8_t)0x06)
#define LVD_REF_SEL_3V0                 ((uint8_t)0x07)
#define IS_LVD_REF_SEL(SEL)            (((SEL) == LVD_REF_SEL_1V7) || ((SEL) == LVD_REF_SEL_1V8) ||\
                                        ((SEL) == LVD_REF_SEL_2V0) || ((SEL) == LVD_REF_SEL_2V2) ||\
                                        ((SEL) == LVD_REF_SEL_2V4) || ((SEL) == LVD_REF_SEL_2V6) ||\
                                        ((SEL) == LVD_REF_SEL_2V8) || ((SEL) == LVD_REF_SEL_3V0))
 
#define LVD_ACT_MODE_INT                ((uint8_t)0x00)
#define LVD_ACT_MODE_RESET              ((uint8_t)0x01)
#define IS_LVD_ACT_MODE(MODE)          (((MODE) == LVD_ACT_MODE_INT) || ((MODE) == LVD_ACT_MODE_RESET))

#define IS_LVD_FILTER_NUMBER(NUMBER)    ((NUMBER) <= (uint16_t)0x3FF)
/**
  * @}
  */

/**
  * @}
  */

/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */

/* Function used to set the PWR configuration to the default reset state ******/
void PWR_DeInit(void);

/* register Access function **********************************************/
void PWR_AccessCmd(FunctionalState NewState);

void PWR_SetSramRetainMode(uint8_t Sram_Mode);

/* LDO configuration functions ************************************************/
void PWR_SwitchLDOStatus(uint16_t PWR_LDO);
void PWR_SET_LDOTrimValue(uint32_t source);

/* WakeUp pins configuration functions ****************************************/

/* Low Power modes configuration functions ************************************/
void PWR_EnterSleepMode(uint32_t PWR_Mode);
void PWR_EnterSTOPMode(uint32_t PWR_Mode, uint8_t PWR_STOPEntry);
void PWR_EnterRunMode(uint32_t PWR_Mode);

void PWR_SET_LDOTrimValue(uint32_t source);

/* Flags management functions *************************************************/
FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);
void PWR_ClearFlag(uint32_t PWR_FLAG);
void PWR_LVDConfig(LVD_Config_U uLVD);
void PWR_LVDCmd(FunctionalState NewState);
void LVD_ClearITPendingBit(void);
#ifdef __cplusplus
}
#endif

#endif /* __XS32L010_PWR_H */

/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT CHIPAT *****END OF FILE****/

